import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MyThread {
  Frame frame = new Frame();



    public void init(){
        TextField textField = new TextField();
        Choice choice = new Choice();
        choice.setBounds(200,200,200,200);
        choice.add("张相程");
        choice.add("王显龙");
        choice.add("李嘉鑫");

        textField.addTextListener(new TextListener() {
            @Override
            public void textValueChanged(TextEvent e) {
                String text = textField.getText();
                System.out.println("text = " + text);
            }
        });
        choice.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                Object item = e.getItem();
                System.out.println("item = " + item);
            }
        });
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                super.windowOpened(e);
                System.out.println("BUYAO");
            }

            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                System.exit(1);
            }

            @Override
            public void windowClosed(WindowEvent e) {
                super.windowClosed(e);
                System.out.println("TINGXIA");
            }
        });
        Box vbox = Box.createHorizontalBox();
        vbox.add(textField);
        vbox.add(choice);
        frame.add(vbox);
        frame.setBounds(500,500,500,500);
        frame.pack();
        frame.setVisible(true);
    }


    public static void main(String[] args) {
        new MyThread().init();
    }

}
